package 队列;

/*
 *1.定义链表节点的结构(单链表)
 * 2.定义队列结构
 * 3.定义队列操作
 */
public class LinkedListQueue {

    private int size;
    private Node head;
    private Node tail;

    public LinkedListQueue() {
        this.head = null;
        this.tail = null;
    }

    //入队列
    public boolean enqueue(Object element){
        Node node = new Node(element,null);
        if (tail==null) {
            tail = node;
            head = node;
        }else {
            tail.next = node;
            tail = node;
        }
        size++;
        return true;
    }

    //出队列
    public Object dequeue(){
        if (head == null){
            return null;
        }
        Object data = head.data;
        head = head.next;
        if (head==null){
            tail = null;
        }
        size--;
        return true;
    }

    static class Node{
        private Object data;
        private Node next;

        public Node(Object data, Node next) {
            this.data = data;
            this.next = next;
        }
    }
}
